<template>
  <div>
    <FormTable :formData="formData"
               :columnData="columnData"
               :url="$api.product_type_getlist"
               :editData="editData"
               :new_url="this.$api.product_type_insert"
               :detail_url="this.$api.product_type_info"
               :edit_url="this.$api.product_type_save"
               :is_default_edit="true"
               label-width="140px"
               :pageConfig="pageConfig"></FormTable>
  </div>
</template>

<script>
export default {
  data () {
    return {
      formData: [
        {
          name: "name",
          label: "会员类型名称",
          value: "",
          type: "input",
        },
        {
          name: "rights_name",
          label: "权益名称",
          value: "",
          type: "input",
        },
        {
          name: "display",
          label: "是否显示",
          value: '',
          type: "select",
          groups: [
            {
              label: '所有',
              value: ''
            },
            {
              label: '显示',
              value: 1
            },
            {
              label: '隐藏',
              value: 0
            },
          ]
        },
      ],
      columnData: [
        {
          prop: "product_type_id",
          label: "id"
        },
        {
          prop: "name",
          label: "权益会员类型标题",
          width:'160px'
        },
        {
          prop: "rights_name",
          label: "权益名称"
        },
        {
          prop: "display",
          label: "是否显示",
          custom: true,
          type: 'switch',
          url: this.$api.product_type_status
        },
        {
          prop: "sort",
          label: "排序",
          custom: true,
          type: 'input',
          url: this.$api.product_type_sort
        },
        {
          prop: 'btn_group',
          label: '操作',
          custom: true,
          type: 'btn_group',
          width:'200px',
          group: [
            {
              name: '编辑',
              type: 'edit',
              color: 'primary',
              detail_mark: 'product_type_id',
            },
            {
              name: '删除',
              type: 'delete',
              color: 'danger',
              url: this.$api.product_type_status
            }
          ]
        }
      ],
      editData: [
        {
          name: "product_type_id",
          label: "权益会员类型id",
          value: "",
          type: "input",
          display:'none'
        },
        {
          name: "rights_id",
          label: "会员类型",
          value: "",
          type: "select",
          groups:[],
          config:{
            filterable:true
          },
          rules:[
            { required: true, message: "请选择会员类型", trigger: "blur" },
          ]
        },
        {
          name: "name",
          label: "会员类型名称",
          value: "",
          type: "input",
          rules:[
            { required: true, message: "请输入会员类型", trigger: "blur" },
          ]
        },
        {
          name: "sort",
          label: "排序",
          value: "",
          type: "input",
        },
        {
          name: "display",
          label: "是否显示",
          value: '',
          type: "select",
          groups: [
            {
              label: '显示',
              value: '1'
            },
            {
              label: '隐藏',
              value: '0'
            },
          ]
        },
      ],
      pageConfig: {
        page: 1,
        pagesize: 10,
      }
    };
  },
  created () {
    this.category_getlist();
  },
  methods: {
    // 获取权益分类
    category_getlist () {
      this.$req.get(this.$api.rights_getnopagelist).then(res => {
        console.log(res);
        let data = res.data;
        for (var i in data) {
          this.editData[1].groups.push({
            label: data[i].name,
            value: data[i].rights_id
          })
        }
      })
    },
    handleSizeChange (e) {
      console.log(e);
    },
    handleCurrentChange (e) {
      console.log(e);
    },
    submit (e) {
      console.log(e);
    },
    reset (e) {
      console.log(e);
    }
  }
}
</script>

<style lang="scss" scoped>
</style>